#include <stdlib.h>
+#ifndef _WIN32
+
+static const pthread_mutexattr_t *
+get_mutex_attr (void)
+{
+ static pthread_mutexattr_t mutexattr;
+ static int initialized = 0;
+
+ if (!initialized)
+ {
+ /* On some platforms, this will keep an allocation till process
+ termination, but it isn't a growing leak. */
+ pthread_mutexattr_init (&mutexattr);
+ pthread_mutexattr_settype (&mutexattr, PTHREAD_MUTEX_RECURSIVE);
+ initialized = 1;
+ }
+
+ return &mutexattr;
+}
+
+#endif
+
BablMutex *
babl_mutex_new (void)
{
#ifdef _WIN32
InitializeCriticalSection (mutex);
#else
- pthread_mutexattr_t mutexattr;
-
- pthread_mutexattr_init (&mutexattr);
- pthread_mutexattr_settype (&mutexattr, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init (mutex, &mutexattr);
- pthread_mutexattr_destroy (&mutexattr);
+ pthread_mutex_init (mutex, get_mutex_attr ());
#endif
return mutex;
}